<%--
  - Author		:	Jaewon Choi
  - Date			:
  - Description	:	
  --%>
<%@ page language="java" %>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/pages/includes/taglibs.jspf" %>
<%@ include file="/WEB-INF/pages/includes/variables.jspf" %>
<%@ include file="/WEB-INF/pages/includes/doctype.jspf" %>
<html>
	<head>
<%@ include file="/WEB-INF/pages/includes/metatags.jspf" %>
		<title><fmt:message key="pages.title" /></title>
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirStyles}/common.css" />" />

		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-1.7.2.min.js" />"></script>
		<script type="text/javascript">
			$(function(){
			});

			function validation(){
				<c:if test="${param.fAct eq 'view'}">
					return true;
				</c:if>
				try{
					with(document.frm) {
						/*
						if(! chkContNmFlag){
							alert("[고객명]은 중복될 수 없습니다.");
							name.focus();
							return false;
						}
						*/
						if((name.value).replace(/\s/g, '') == ""){
							alert("[회원사명]은 필수 입력 항목입니다.");
							name.focus();
							return false;
						}
					}
				}catch(err){
					return false;	
				}
				
				return confirm(confirmMsg);
			}
			
			function goUsers(userIdx){
				if(userIdx){
					document.userFrm.idx.value = userIdx;
					document.userFrm.submit();	
				}
			}
			
			var confirmMsgs = ["등록 하시겠습니까?", "수정 하시겠습니까?", "삭제 하시겠습니까?"];
			var confirmMsg = "";
		</script>
	</head>
	<body>
		<div class="bodyWrap">
<%@ include file="/WEB-INF/pages/includes/header.jsp" %>
<%@ include file="/WEB-INF/pages/includes/left.jsp" %>
			<div class="contWrap">
				<div class="menuTitle">
					회원사관리 - 회원사
					<c:choose>
						<c:when test="${param.fAct eq 'view'}">상세보기</c:when>
						<c:when test="${not empty customer}">수정</c:when>
						<c:otherwise>등록</c:otherwise>
					</c:choose>
				</div>
				<form id="frm" name="frm" method="post" enctype="multipart/form-data" action="<c:url value="/customer/submit.do" />" onsubmit="return validation();">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="searchUserId" value="${param.searchUserId}" />
					<input type="hidden" name="searchName" value="${param.searchName}" />
					<input type="hidden" name="idx" value="${customer.idx}">
					<table class="frmTbl" border="0">
						<colgroup>
							<col width="176px;" />
							<col width="*" />
						</colgroup>
						<tbody>
							<tr>
								<th>회원사</th>
								<td>
									<c:choose>
										<c:when test="${param.fAct eq 'view'}">
											${customer.name}
										</c:when>
										<c:otherwise>
											<input type="text" name="name" value="${customer.name}" maxlength="15" title="회원사명 입니다." />
										</c:otherwise>
									</c:choose>
								</td>
							</tr>
							 <tr>
								<th>설명</th>
								<td>
									<c:choose>
										<c:when test="${param.fAct eq 'view'}">
											<c:forEach items="${fn:split(customer.contDesc, ',')}" var="appId">
												${customer.contDesc}<br />
											</c:forEach>
										</c:when>
										<c:otherwise>
											<!-- <c:forEach items="${appList}" var="app">
												<label>
													<input type="checkbox" name="appIds" value="${app.appId}" <c:if test="${fn:contains(customer.appIds, app.appId)}"> checked="checked" </c:if> />${app.appId}
												</label><br />
											</c:forEach> -->
											<textarea name="contDesc" maxlength="1000" style="width:660px;height: 70px;">${customer.contDesc}</textarea>
										</c:otherwise>
									</c:choose>
								</td>
							</tr>
							<!-- <tr>
								<th>App IDs</th>
								<td>
									<c:choose>
										<c:when test="${param.fAct eq 'view'}">
											<c:forEach items="${fn:split(customer.appIds, ',')}" var="appId">
												${appId}<br />
											</c:forEach>
										</c:when>
										<c:otherwise>
											<c:forEach items="${appList}" var="app">
												<label>
													<input type="checkbox" name="appIds" value="${app.appId}" <c:if test="${fn:contains(customer.appIds, app.appId)}"> checked="checked" </c:if> />${app.appId}
												</label><br />
											</c:forEach>
										</c:otherwise>
									</c:choose>
								</td>
							</tr> -->
						</tbody>
					</table>
					<c:choose>
						<c:when test="${empty customer}">
							<input type="button" class="btn" value="취소" onclick="javascript:document.listFrm.submit();" />
							<input type="submit" class="btn" value="등록" onclick="javasciprt:confirmMsg=confirmMsgs[0];"/>
						</c:when>
						<c:when test="${param.fAct eq 'view'}">
							<input type="button" class="btn" value="목록" onclick="javascript:document.listFrm.submit();" />
							<input type="submit" class="btn" value="수정" onclick="javasciprt:document.frm.action='<c:url value="/customer/form.do" />';" />
						</c:when>
						<c:otherwise>
							<input type="button" class="btn" value="취소" onclick="javascript:document.listFrm.submit();" />
							<input type="submit" class="btn" value="수정" onclick="javasciprt:confirmMsg=confirmMsgs[1];"/>
							<input type="button" class="btn" value="삭제" onclick="javascript:if(confirm(confirmMsgs[2])){document.removeFrm.submit();}" />
						</c:otherwise>
					</c:choose>
				</form>
				<br />
				<div><strong>회원사별 이용자 관리</strong></div>
				<form name="removeUserFrm" action="<c:url value="/users/remove.do" />" method="post">
					<table class="listTbl" border="0" style="margin: 10px 0 0;">
						<colgroup>
							<col width="*" />
							<col width="136px;" />
							<col width="272px" />
							<col width="136px;" />
							<col width="128px;" />
						</colgroup>
						<thead>
							<tr>
								<th>No.</th>
								<th>아이디</th>
								<th>이름</th>
								<th>등록자</th>
								<th>등록일</th>
							</tr>
						</thead>
						<tbody>
							<c:choose>
								<c:when test="${fn:length(usersList) ne 0}">
									<c:forEach items="${usersList}" var="users" varStatus="stat">
										<tr>
											<td>${stat.count}</td>
											<td onclick="javascript:goUsers(${users.idx});">${users.id}</td>
											<td onclick="javascript:goUsers(${users.idx});">${users.name}</td>
											<td onclick="javascript:goUsers(${users.idx});">${users.createdId}</td>
											<td onclick="javascript:goUsers(${users.idx});">${users.createdTime}</td>
										</tr>
									</c:forEach>	
								</c:when>
								<c:otherwise>
									<tr><td colspan="6" style="text-align: center;">데이터가 없습니다.</td></tr>
								</c:otherwise>
							</c:choose>
						</tbody>
					</table>
				</form>
				
				<form name="listFrm" action="<c:url value="/customer/list.do" />" method="post" style="display: none;">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="name" value="${param.searchName}" />
					<input type="hidden" name="appIds" value="${param.searchAppIds}" />
				</form>
				
				<form name="removeFrm" action="<c:url value="/customer/remove.do" />" method="post" style="display: none;">
					<input type="hidden" name="fAct" value="remove">
					<input type="hidden" name="idx" value="${customer.idx}">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="searchName" value="${param.searchName}" />
					<input type="hidden" name="searchAppIds" value="${param.searchAppIds}" />
				</form>
				
				<form name="userFrm" action="<c:url value="/users/form.do" />" method="post" style="display: none;">
					<input type="hidden" name="idx" value="" />
				</form>
				
			</div>
<%@ include file="/WEB-INF/pages/includes/footer.jsp" %>
		</div>
	</body>
</html> 